﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_Data : ATPages
{
    ZSql zs = new ZSql();
    ZSql count = new ZSql();
    ZSql jc = new ZSql();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            initData();
        }
    }
    private void initData()
    {
        string txt = "";
        string txt1 = DateTime.Now.ToShortDateString();
        if (!string.IsNullOrEmpty(Request["id"]))
        {
            jc.Open("select brand,comodname,modul,unit,number,prices,gifts,guestName,GuestMan,phone,address,TotalMoney from CS_Sales  a join CS_Guest b on a.guestid=b.GuestId where SalesCode='" + Request["id"] + "'");
            if (jc.m_table.Rows.Count > 0)
            {
                zs.Open("select brand,comodname,modul,unit,number,prices,gifts,convert(varchar(10),DeliveryDate,120) as DeliveryDate,guestName,GuestMan,phone,address,TotalMoney from CS_Sales  a join CS_Guest b on a.guestid=b.GuestId where IsOut=0 and SalesCode='" + Request["id"] + "'");
                if (zs.m_table.Rows.Count > 0)
                {
                    count.Open("select sum(number)as num,sum(TotalMoney)as price from CS_Sales where IsOut=0 and SalesCode='" + Request["id"] + "' group by SalesCode");
                    txt += "<table class=\"gridview\" cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"width:100%;border-collapse:collapse;\"><tr><th width=\"106\">品牌</th><th width=\"102\">规格及型号</th><th width=\"41\">单位</th><th width=\"41\">数量</th><th width=\"69\">单价</th><th width=\"84\">金额</th><th width=\"71\">联系人</th><th width=\"85\">联系电话 </th><th width=\"85\">地址 </th><th width=\"85\">备注</th></tr>";
                    for (int i = 0; i < zs.m_table.Rows.Count; i++)
                    {

                        txt += " <tr align=\"center\"><td >" + zs.m_table.Rows[i]["brand"].ToString() + "</td><td>" + zs.m_table.Rows[i]["modul"].ToString() + "</td><td>" + zs.m_table.Rows[i]["unit"].ToString() + "</td><td>" + zs.m_table.Rows[i]["number"].ToString() + "</td><td>" + zs.m_table.Rows[i]["prices"].ToString().Substring(0, zs.m_table.Rows[i]["prices"].ToString().Length - 2) + "</td><td>" + zs.m_table.Rows[i]["TotalMoney"].ToString().Substring(0, zs.m_table.Rows[i]["TotalMoney"].ToString().Length - 2) + "</td><td>" + zs.m_table.Rows[i]["GuestMan"].ToString() + "</td><td>" + zs.m_table.Rows[i]["phone"].ToString() + "</td><td>" + zs.m_table.Rows[i]["address"].ToString() + "</td><td>" + zs.m_table.Rows[i]["gifts"].ToString() + "</td></tr>";
                    }
                    if (count.m_table.Rows.Count > 0)
                    {
                        txt += " <tr><td colspan=\"3\">本页小计</td><td colspan=\"2\">" + count.m_table.Rows[0]["num"].ToString() + "</td><td colspan=\"5\">" + count.m_table.Rows[0]["price"].ToString().Substring(0, count.m_table.Rows[0]["price"].ToString().Length - 2) + "</td></tr><tr><td colspan=\"3\">本页合计</td><td colspan=\"2\">" + count.m_table.Rows[0]["num"].ToString() + "</td><td colspan=\"5\">" + count.m_table.Rows[0]["price"].ToString().Substring(0, count.m_table.Rows[0]["price"].ToString().Length - 2) + "</td></tr></table>";
                        txt1 = zs.m_table.Rows[0]["DeliveryDate"].ToString();
                    }
                }
                else
                {
                    txt = "该单号商品已经出库";
                }
            }
            else
            {
                txt = "该单号输入错误";
            }
            txt += "," + txt1;
            zs.Close();
            count.Close();
        }
        Response.Write(txt);
        Response.End();
    }
}
